import dayjs from "dayjs"

// 返回当前一天时间
export function getTodayStartAndEndTime() {
    var today = new Date();

    // 获取零点时间
    var startOfDay = new Date(today.getFullYear(), today.getMonth(), today.getDate());

    // 获取当天23:59:59的时间
    var endOfDay = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59);
    // 格式化时间
    function format(date: any) {
        return [
            date.getFullYear(),
            ('0' + (date.getMonth() + 1)).slice(-2),
            ('0' + date.getDate()).slice(-2)
        ].join('-') + ' ' + [
            ('0' + date.getHours()).slice(-2),
            ('0' + date.getMinutes()).slice(-2),
            ('0' + date.getSeconds()).slice(-2)
        ].join(':');
    }

    var startFormatted = format(startOfDay);
    var endFormatted = format(endOfDay);

    return {
        startOfDay: startFormatted,
        endOfDay: endFormatted
    };
}
// 返回最近三天
export function get3Day() {
    let today = new Date();
    // 获取今天的日期
    let startOfDay = dayjs(today).startOf('day'); // 获取今天开始的时间点

    // 计算前两天的时间戳
    let twoDaysAgo = startOfDay.subtract(2, 'day').startOf('day');
    let threeDaysAgo = startOfDay.subtract(3, 'day').endOf('day'); // 最近三天的第一天结束的时间点

    // 格式化日期
    let formattedThreeDaysAgo = threeDaysAgo.format("YYYY-MM-DD HH:mm:ss");
    let formattedToday = dayjs(today).format("YYYY-MM-DD HH:mm:ss");
    return {
        startOfDay: formattedThreeDaysAgo,
        endOfDay: formattedToday
    };
}
// 返回最近三十天
export function get30Day() {
    let today: any = new Date();
    const startOfDayToday = new Date(today.getFullYear(), today.getMonth(), today.getDate());
    let startOfDay30DaysAgo: any = new Date(startOfDayToday);
    startOfDay30DaysAgo.setDate(startOfDay30DaysAgo.getDate() - 29);
    startOfDay30DaysAgo = dayjs(startOfDay30DaysAgo).format("YYYY-MM-DD HH:mm:ss")
    today = dayjs(today).format("YYYY-MM-DD HH:mm:ss")
    return {
        startOfDay: startOfDay30DaysAgo,
        endOfDay: today
    };
}
export function getNowDay(){
    let today = new Date();
    // 获取今天的开始时间
    let startOfDay = dayjs(today).startOf('day').format("YYYY-MM-DD 00:00:00");

    // 获取今天的结束时间
    let endOfDay = dayjs(today).endOf('day').format("YYYY-MM-DD 23:59:59");
    return {
        startOfDay: startOfDay,
        endOfDay: endOfDay
    };
}